#ifndef WIN_SYSTEM_H
#define WIN_SYSTEM_H
#define _WIN32_IE 0x300

#include <windows.h>
#include <wingdi.h>
#include "exceptions.h"
namespace sys
{
	class RegistryKey
	{
		private:
			HKEY _hkey;
			void GetValue(const char * entry_name, DWORD &type, BYTE * buffer, DWORD size);
			void SetValue(const char * entry_name,
								DWORD type, const BYTE * buffer, DWORD size);
			void Init(const HKEY parentKey, const char * path);
		public:
			RegistryKey(const HKEY parentKey, const char * path);
			RegistryKey(const char * path);
			int GetIntValue(const char * entry_name);
			void GetValue(const char * entry_name, 
   					char * result, const int size);
			void SetValue(const char * entry_name, const int value);
			void SetValue(const char * entry_name, const char * value);
			~RegistryKey();
	};
	
	class Point : public POINT
	{
		public:
			Point(const long px=0, const long py=0){x=px, y=py;}
			void Subtract(const Point &p);
			void Add(const Point &p);
			void Set(const long px, const long py);
	};


	Point operator- (const Point &, const Point &);
	Point operator+ (const Point &, const Point &);

	class Rect : public RECT
	{
		public:
			Rect();
			Rect(const int l, const int t, const int r, const int b,
	             const bool isSize = false);
			void SetLeftTop(const Point& p);
			void SetRightBottom(const Point& p);
			void Set(const int left,
	  				 const int top,
	                 const int right,
	                 const int bottom);
			void SetSquare(const Point& pos, const int size);
			void Subtract(const Rect &r1, const Rect &r2);
			void Subtract(const Rect &r);
			void Move(const Point &p);
			void Move(const Rect &r);
			void MoveTo(const Point &p); 
			void MoveTo(const Rect &r);
			void MoveTo(const int x, const int y);
			Rect &operator-=(const Rect &r)
				{Subtract(r); return *this;}
			void Inflate(const int size);
			int Width() const
				{ return right - left; }
			int Height() const
				{ return bottom - top; }
	};

	class system_error : public runtime_error_ex
	{
		public:
			system_error();
			system_error(const LONG errorCode);
			system_error(const char * text);
			system_error(const char * text, const LONG errorCode);
		private:
  			void init(const char *, const LONG errorCode);
	};
}
#endif
